<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * @abstract 状态API
 * @author zxj
 *
 */
class Status extends CI_Controller {
	function __construct() {
		parent::__construct();
	}

    /**
     * 订单状态列表
     */
    function index()
    {
        $gpData = gp();
        $table = $gpData['type']=='order'?'mt_order_status':'mt_product_status';
        $dataList = $this->common_model->selectCustom($table, array('available' => 1));
        $data['dataList'] = $dataList;
        //json判断处理
        if (empty($dataList)) {
            $message = 'No more data!';
        } else {
            $message = 'return succeed!';
            $status = 1;
        }
        json_output($data, $message, $status);
    }


    /**
     * 获取维修轨迹
     */
    function trackList(){
        $param = gp();
        $oid = (int)$param['oid'];
        $pid = (int)$param['pid'];
        //one track or all track
        if(!$pid && !$oid){
            json_output($pid,'oid or pid not empty',false);
        }
        $where = $oid?array('oid'=>$oid):array('pid'=>$pid);
        //#维修轨迹
        $dataList = $this->common_model->selectCustom('mt_product_track', $where);
        foreach ($dataList as &$rs) {
            $startStatus = $this->common_model->selectFirst('mt_product_status', array('id' => $rs['start_sid']));
            $rs['startName_ch'] = $startStatus['name_ch'];
            $rs['startName_en'] = $startStatus['name_en'];
            $rs['startName_es'] = $startStatus['name_es'];
            $endStatus = $this->common_model->selectFirst('mt_product_status', array('id' => $rs['end_sid']));
            $rs['endName_ch'] = $endStatus['name_ch'];
            $rs['endName_en'] = $endStatus['name_en'];
            $rs['endName_es'] = $endStatus['name_es'];
            $rs['is_sync'] = $rs['is_sync'] ? 'Yes' : 'No';
            $rs['add_time'] = date('Y-m-d H:i:s', $rs['add_time']);
        }
        unset($rs);
        //json判断处理
        if (empty($dataList)) {
            $message = 'No more data!';
        } else {
            $message = 'return succeed!';
            $status = 1;
        }
        json_output($dataList, $message, $status);
    }



}
